package com.SeleniumTestsGoogleChrome;

import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.SeleneseTestBase;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.util.regex.Pattern;

import com.thoughtworks.selenium.SeleneseTestBase;

public class PopularDestinationTestCases extends SeleneseTestBase {

	@Before
	public void setUp() throws Exception {
		File file = new File(
				"C:/Users/Steven/Documents/4th Year/EECE 419/chromedriver.exe");
		System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
		WebDriver driver = new ChromeDriver();
		String baseUrl = "http://localhost:8080/Website/";
		selenium = new WebDriverBackedSelenium(driver, baseUrl);
	}
	
	@Test
	public void test7() throws Exception {
		// Created by Steven Chow
		// Scenario 1: Popular Destinations displayed
		// Test Case 1: User requests popular destinations

		// Go to website
		selenium.open("/Website/index.html");
		// Login as an Admin
		selenium.click("css=div.page-region");
		selenium.click("css=div.tile.bg-color-yellow > div.tile-content.icon");
		selenium.waitForPageToLoad("30000");
		selenium.type("name=id", "1");
		selenium.type("name=password", "pass0");
		selenium.click("css=input[type=\"submit\"]");
		selenium.waitForPageToLoad("30000");
		// Are we in the Manager Portal?
		assertEquals("Manager Portal", selenium.getTitle());
		// Is the Popular Destinations Button there?
		assertTrue(selenium.isElementPresent("//a[2]/div/div"));
		selenium.click("//a[2]/div/div");
		selenium.waitForPageToLoad("30000");
		// Check if we are in the right page
		assertEquals("Popular Destination", selenium.getTitle());
		// Check if we get the right info displayed.
		assertEquals(
				"BlueBearLand",
				selenium.getText("//html/body/div/div[2]/div/table/tbody/tr/td/div/div/div[2]/div"));
		// Check if there are any other elements. There should be none
		assertFalse(selenium.isTextPresent("Vancouver"));
		assertFalse(selenium.isTextPresent("Los Angeles"));

	}

	// Created by Steven Chow
	// Scenario 2: Popular Destinations not displayed
	// Test Case 2: User requests popular destinations while there is no
	// data
	@Test
	public void test8() throws Exception {
		// Go to website
		selenium.open("");
		// Login as an Admin
		selenium.click("css=div.page-region");
		selenium.click("css=div.tile.bg-color-yellow > div.tile-content.icon");
		selenium.waitForPageToLoad("30000");
		selenium.type("name=id", "1");
		selenium.type("name=password", "pass0");
		selenium.click("css=input[type=\"submit\"]");
		selenium.waitForPageToLoad("30000");
		// Are we in the Manager Portal?
		assertEquals("Manager Portal", selenium.getTitle());
		// Is the Popular Destinations Button there?
		assertTrue(selenium.isElementPresent("//a[2]/div/div"));
		selenium.click("//a[2]/div/div");
		selenium.waitForPageToLoad("30000");
		// Check if we are in the right page
		assertEquals("Popular Destination", selenium.getTitle());
		// Check if we get the right info displayed.
		assertFalse(selenium.isTextPresent("BlueBearLand"));
		// Check if there are any other elements. There should be none
		assertFalse(selenium.isTextPresent("Vancouver"));
		assertFalse(selenium.isTextPresent("Los Angeles"));
	}


	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
